﻿package net.steam.easyjoboa.web.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import net.steam.easyjoboa.biz.EmployeeBiz;
import net.steam.easyjoboa.biz.RolesBiz;
import net.steam.easyjoboa.entity.Employee;
import net.steam.easyjoboa.entity.Roles;

public class RolesAction {

	private RolesBiz rolesBiz;
	private Roles roles;
	private EmployeeBiz employeeBiz;
	private Employee employee;



	/**
	 * 添加角色
	 * @return
	 */
	@Action(value = "addRoles", results = {
			@Result(name = "input", location = "/error.jsp"),
			@Result(name = "success", location = "/sys_addRoles.jsp") })
	public String addRoles() {
		int key = rolesBiz.addRoles(roles);
		if (key > 0) {
			return "success";
		} else {
			return "input";
		}
	}
	/**
	 * 加载所有的角色，并跳到更新页面
	 * 
	 * @return
	 */
	private int key;
	List<Roles> roleses;

	@Action(value = "payRoles", results = {
			@Result(name = "input", location = "/error.jsp"),
			@Result(name = "success", location = "/sys_updateRoles.jsp") })
	public String payRoles() {
		employee = employeeBiz.findEmployeeById(key);
		roleses = rolesBiz.findAllRoles();
		return "success";
	}

	/**
	 * 
	 * 分配用户角色
	 * @return
	 */
	private int[] id;
	@Action(value = "dealRoles", results = {
			@Result(name = "input", location = "/error.jsp"),
			@Result(name = "success", location = "findByPage",type="redirectAction") })
	public String dealRoles() {
		List<Roles> list = rolesBiz.findById(id);
		employee=employeeBiz.findEmployeeById(key);
		employee.setRoleses(list);
		employeeBiz.updateEmployee(employee);
		return "success";
	}


	/**
	 * 加载所有的角色
	 */
	private List<Roles> roles_list;

	@Action(value = "findAllRoles", results = {
			@Result(name = "input", location = "/error.jsp"),
			@Result(name = "success", location = "/sys_updateRoles.jsp") })
	public String findAllRoles() {
		roles_list = rolesBiz.findAllRoles();
		if (roles_list.size() == 0) {
			return "input";
		} else {
			return "success";
		}
	}

	
	
	public void setRolesBiz(RolesBiz rolesBiz) {
		this.rolesBiz = rolesBiz;
	}

	public Roles getRoles() {
		return roles;
	}

	public void setRoles(Roles roles) {
		this.roles = roles;
	}

	public List<Roles> getRoles_list() {
		return roles_list;
	}

	public void setRoles_list(List<Roles> roles_list) {
		this.roles_list = roles_list;
	}



	public Employee getEmployee() {
		return employee;
	}



	public void setEmployee(Employee employee) {
		this.employee = employee;
	}



	public int getKey() {
		return key;
	}



	public void setKey(int key) {
		this.key = key;
	}



	public List<Roles> getRoleses() {
		return roleses;
	}



	public void setRoleses(List<Roles> roleses) {
		this.roleses = roleses;
	}



	public int[] getId() {
		return id;
	}



	public void setId(int[] id) {
		this.id = id;
	}



	public void setEmployeeBiz(EmployeeBiz employeeBiz) {
		this.employeeBiz = employeeBiz;
	}

}
